<?php if (!defined('THINK_PATH')) exit();?>   <!-- Main content -->
    <section class="content">

	  <div class="row">
        <div class="col-xs-12">
          <div class="box box-info">
            <div class="box-header">
              <h3 class="box-title">权限管理</h3> &emsp;<button type="button" data-toggle="modal" data-target="#exampleModal" class="btn btn-sm btn-success">新建权限</button>&emsp;<button type="button" data-toggle="modal" data-target="#singlModal" class="btn btn-sm btn-success">新建分类</button>

              <div class="box-tools">
                <button type="button" id="refresh" class="btn btn-default btn-sm" title="刷新当前页"><i class="fa fa-refresh"></i></button>
              </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
              <table class="table table-hover">
               <tbody><tr>
					         <th>权限名</th>
                   <th>权限ID</th>
                  <th>权限Name</th>
                  <th>状态</th>
				          <th>操作</th>
                </tr>


          <?php if(is_array($class)): $i = 0; $__LIST__ = $class;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr><td><?php echo ($vo["classname"]); ?></td><td></td><td></td><td></td><td><a href="/index.php/admin/admin/getrulecl/<?php echo ($vo["classid"]); ?>" class="btn btn-success btn-xs ajax_return">修改</a></td></tr>
              <?php if(is_array($vo['rules'])): $i = 0; $__LIST__ = $vo['rules'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$rul): $mod = ($i % 2 );++$i;?><tr>
                  <td>&emsp;├─<?php echo ($rul["title"]); ?></td>
                  <td><?php echo ($rul["id"]); ?></td>
                  <td><?php echo ($rul["name"]); ?></td>
                  <td><?php switch($rul["status"]): case "1": ?><span class="btn btn-success btn-xs">正常</span><?php break;?>
                      <?php case "0": ?><span class="btn btn-danger btn-xs">禁用</span><?php break; endswitch;?></td>
                  <td>
                    <a href="/index.php/admin/admin/getrule/<?php echo ($rul["id"]); ?>" class="btn btn-success btn-xs ajax_return">修改</a>
                    <a href="/index.php/admin/admin/rulestate/<?php echo ($rul["id"]); ?>" class="btn btn-warning btn-xs ajax_return">开启/禁用</a>
                    <a href="/index.php/admin/admin/delrule/<?php echo ($rul["id"]); ?>" class="btn btn-danger btn-xs ajax_return">删除</a>
                  </td>
                  </tr><?php endforeach; endif; else: echo "" ;endif; endforeach; endif; else: echo "" ;endif; ?>

              </tbody></table>
            </div>
            <!-- /.box-body -->

          </div>
          <!-- /.box -->
        </div>
      </div>

    </section>
    <!-- /.content -->

<div class="modal modal-success fade" id="exampleModal" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form class="form-horizontal" id="addrules" method="post" action="/index.php/Admin/admin/addrule">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" >新建权限</h4>
      </div>
              <div class="modal-body">
                <div class="form-group">
                  <label for="inputtitle" class="col-sm-2 control-label">权限名</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" name="title" id="inputtitle" placeholder="分类名">
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputname" class="col-sm-2 control-label">权限</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" name="name" id="inputname" placeholder="如 Admin/admin/index">
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label">权限类别</label>
                  <div class="col-sm-10">
                 <select class="form-control" name="classid">
                      <?php if(is_array($class)): $i = 0; $__LIST__ = $class;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($vo["classid"]); ?>"><?php echo ($vo["classname"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
                </select>
                  </div>
                </div>
                </div>
              <!-- /.modal-body -->
              <div class="modal-footer">
                <p class="pull-left ajaxreturnp"></p>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-info pull-right subtn">确定</button>
              </div>
              <!-- /.box-footer -->
            </form>
      </div>
    </div>
  </div>
</div>
<!--exampleModal-->

<div class="modal modal-success fade" id="singlModal" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form class="form-horizontal" id="addclass" method="post" action="/index.php/Admin/admin/addruleclass">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" >新建分类</h4>
      </div>
              <div class="modal-body">
                <div class="form-group">
                  <label for="inputtitle2" class="col-sm-2 control-label">分类名</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" name="title" id="inputtitle2" placeholder="权限名">
                  </div>
                </div>
                </div>
              <!-- /.modal-body -->
              <div class="modal-footer">
                <p class="pull-left ajaxreturnp"></p>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-info pull-right subtn">确定</button>
              </div>
              <!-- /.box-footer -->
            </form>
      </div>
    </div>
  </div>
</div>
<!--singlModal-->
<div class="modal modal-success fade" id="rulecllModal" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form class="form-horizontal" id="addclass" method="post" action="/index.php/Admin/admin/editruleclass">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" >修改分类</h4>
      </div>
              <div class="modal-body">
              <input type="hidden" name="id" id="inputhidden3">
                <div class="form-group">
                  <label for="inputtitle4" class="col-sm-2 control-label">分类名</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" name="title" id="inputtitle4">
                  </div>
                </div>
                </div>
              <!-- /.modal-body -->
              <div class="modal-footer">
                <p class="pull-left ajaxreturnp"></p>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-info pull-right subtn">确定</button>
              </div>
              <!-- /.box-footer -->
            </form>
      </div>
    </div>
  </div>
</div>
<!--editruleclassid-->
<div class="modal modal-success fade" id="editModal" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form class="form-horizontal" id="editrules" method="post" action="/index.php/Admin/admin/editrule">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" >修改权限</h4>
      </div>
              <div class="modal-body">
              <input type="hidden" name="id" id="inputhidden1">

                <div class="form-group">
                  <label for="inputtitle3" class="col-sm-2 control-label">权限名</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" name="title" id="inputtitle3">
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputname3" class="col-sm-2 control-label">权限</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" name="name" id="inputname3">
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label">权限类别</label>
                  <div class="col-sm-10">
                 <select class="form-control" name="classid" id="selectclid">
                      <?php if(is_array($class)): $i = 0; $__LIST__ = $class;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($vo["classid"]); ?>"><?php echo ($vo["classname"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
                </select>
                  </div>
                </div>
                </div>
              <!-- /.modal-body -->
              <div class="modal-footer">
                <p class="pull-left ajaxreturnp"></p>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-info pull-right subtn">确定</button>
              </div>
              <!-- /.box-footer -->
            </form>
      </div>
    </div>
  </div>
</div>
<!--editmodal-->
<div class="modal modal-danger fade" id="deleteModal" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form class="form-horizontal" id="delrules" method="post" action="/index.php/Admin/admin/delrule">
      <input type="hidden" name="id" id="inputhidden2">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">删除权限</h4>
      </div>
      <div class="modal-body">
        <p>确定要删除 [<span id="delruletitle"></span>] 权限吗？删除后不可恢复!</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" class="btn btn-danger subtn">确定删除</button>
      </div>
      </form>
    </div>
  </div>
</div>
<!--deletemodal-->

<script type="text/javascript">
  $(".subtn").on("click",function(){
      var formdata = $(this).parent().parent().serialize();
      var url = $(this).parent().parent().attr("action");
      var method = $(this).parent().parent().attr("method");
      if (method == "post") {
        $.post(url,formdata,function(data){
          if (data == '1') {
            $(".modal").modal('hide');
          }else{
            $(".ajaxreturnp").text("操作失败");
          }
        });
      }else if(method == "get"){
          $.get(url,function(data){
              if (data=='1') {
                $(".modal").modal('hide');
              }else{
                $(".ajaxreturnp").text("操作失败");
              }
          });
      } 
  });

  $(".ajax_return").on("click",function(){
      var url = $(this).attr("href");
      var pathurl = url.split("/");
      /**修改rule**/
      if (pathurl[pathurl.length-2] == "getrule") {
          $.get(url,function(data){
            $("#inputhidden1").val(data.id);
            $("#inputtitle3").val(data.title);
            $("#inputname3").val(data.name);
            $("#selectclid").val(data.classid);
            $("#editModal").modal('show');
          });
      /**删除rule**/
      }else if(pathurl[pathurl.length-2] == "delrule"){
            var rtitle = $(this).parent().siblings().first().text();
            $("#delruletitle").text(rtitle.slice(3));
            $("#inputhidden2").val(pathurl[pathurl.length-1]);
            $("#deleteModal").modal('show');
      /**修改ruleclass**/
      }else if(pathurl[pathurl.length-2] == "getrulecl"){
          var ctitle = $(this).parent().siblings().first().text();
            $("#inputhidden3").val(pathurl[pathurl.length-1]);
            $("#inputtitle4").val(ctitle);
            $("#rulecllModal").modal('show');
      }else{
          if(url&&url!='/'&&url!="#"){
            $.get(url,function(data){
                if (data=='1') {
                  refresh();
                }else{
                  alert("操作失败");
                }
            });
          }
      }
  });

  $('.modal').on('hidden.bs.modal', function (){
      refresh();
  })

  $("#refresh").on("click",function(){
      refresh();
  });

  function refresh(){
      $("#mcont").load("/index.php/Admin/admin/rulelist");
  }
</script>